
//
// 110223 - AH - Created.
//

package org.soekrat.gui.swing.studio;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;

/**
 * <p>
 *   Dialog to show "teared off" 
 *   {@link RatStudioView} from a 
 *   {@link RatStudioViewPane}.  
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
final class RatStudioViewDialog extends JDialog 
{
  private RatStudioViewPane m_pane=null;
  
  private RatStudioView m_view=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  RatStudioViewDialog(){ buildGui(); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param p Dialog's parent.
   */
  RatStudioViewDialog(Frame p){ super(p); buildGui(); }
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param p Dialog's parent.
   */
  RatStudioViewDialog(Dialog p){ super(p); buildGui(); }
  
  // Invoked from constructor.
  private void buildGui()
  {
    setModal(false);
    
    Container c=getContentPane();
    c.setLayout(new BorderLayout());
    
    addWindowListener
    (
      new WindowAdapter() 
      {
        public void windowClosing(WindowEvent e) 
        {
          //getContentPane().removeAll();
          m_pane.putBack(m_view);
          m_view.teared(false);
          dispose();
        }
      }
    );
  }
  
  /**
   * <p>
   *   Shows dialog.
   * </p>
   * @param v View to show in dialog.
   */
  void showDialog(RatStudioView v)
  {
    if (v==null)
    {
      throw new NullPointerException("v");
    }
   
    m_view=v;
    m_pane=v.getContext();
    
    setTitle(v.getTitle());
    
    Container c=getContentPane();
    c.removeAll();
    c.add(v, BorderLayout.CENTER);
    pack();
    setVisible(true);
  }
  
}
